﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<DTO.Models.SURVEY>>" %>


<div class="dung-left">
	<h3></h3>
</div>        
<div class="dung-right">
    <%--<%= Html.ActionLink("Thêm mới","GetForm","Survey", new {ID = 0}, new {@class="dung-button"}) %>--%>
    <input id="addnew" type="button" class="dung-button" onclick="addnew()" value="Thêm mới" />&nbsp;
    <input id="removelist" type="button" class="dung-button" onclick="removemdedia()" value="Xóa" />&nbsp;
</div>
<div class="clearer">&nbsp;</div>
<div>
	<form action="" method="post" id="postlist">
		<table width="100%" class="dung-table">
			<tr>
				<th width="5%"></th>
				<th width="50%">Câu hỏi</th>
				<th width="25%">Thời gian</th>
				<th width="20%">Công cụ</th>
			</tr>
			<tbody>
                <%
                    foreach (var obj in Model)
                    {
                        
                %>
                        <tr>
                            <td>
                                <%= Html.CheckBox("surveyidselect", false, new {value = obj.ID}) %>
                            </td>
                            <td>
                                <%= Html.Encode(obj.Question) %>
                            </td>
                            <td>
                                <%= Html.Encode(string.Format("{0:dd/MM/yyyy H:mm:ss tt}", obj.DateCreate)) %>
                            </td>
                            <td>
                                <%= Html.ActionLink("Cập nhật","GetForm","Survey", new {ID = obj.ID}, new {@class="dung-button"}) %>
                                <% if (!obj.IsTop.Value){ %>
                                <%= Html.ActionLink("Active","Active","Survey", new {ID = obj.ID}, new {@class="dung-button"}) %>
                                <%} %>
                            </td>
                        </tr>
                <%         
                    }
                %>
			</tbody>
		</table>
	</form>
</div>
<div>
    <div class="dung-right">
    <% 
        int totalpage = Convert.ToInt32(ViewData["TotalPage"]);
        int pageindex = Convert.ToInt32(ViewData["PageIndex"]);
        int pagesize = Convert.ToInt32(ViewData["PageSize"]);
        
            
        int th = pageindex / pagesize;
        int begin = 1;
        int max = totalpage;
        if(th - 1 > 0)
        {
            begin = (th - 1) * pagesize;
        }
        if((th + 1) * pagesize < totalpage)
        {
            max = (th + 1) * pagesize;   
        }
    %>
    <% Response.Write("<input type='button' class='dung-button' onclick='loadmediapage(" + 1 + ")' value='|<' />");%>
    <%     
        for(int index = begin; index <= max; index++)
        {
            if(index != pageindex)
            {
                if((index == begin && index % pagesize == 0) || (index == max && index % pagesize == 0))
                {
                    %>
                    <% Response.Write("<input type='button' class='dung-button' onclick='loadmediapage(" + index.ToString() + ")' value='...' />"); %>
                    <%
                }
                else
                {
                    %>
                    <% Response.Write("<input type='button' class='dung-button' onclick='loadmediapage(" + index.ToString() + ")' value='" + index.ToString() + "' />"); %>
                    <%
                }
            }    
            else
            {
                %>
                <% Response.Write("<input type='button' class='dung-button-other' onclick='loadmediapage(" + index.ToString() + ")' value='" + index.ToString() + "' />"); %>
                <%
            }
        }
    %>
	<% Response.Write("<input type='button' class='dung-button' onclick='loadmediapage(" + (totalpage).ToString() + ")' value='>|' />");%>
    
</div>
<div class="clearer">&nbsp;</div>
</div>

<script type="text/javascript">

    function addnew()
    {
        window.location = "/Survey/GetForm/0";
    }

    function removemdedia() {
        var listid = "";
        $("input:checked").each(function () {
            listid += $(this).val() + "-";
        });
        if(listid.length == 0){
            confirm("Vui lòng chọn một item để xóa");
        }
        else
        {
            if(confirm("Bạn có chắc muốn xóa không?") == true)
            {
                $.get("/Survey/Delete/"+ listid, 
                    function (data) {
                        loadmediapage(<%= ViewData["PageIndex"] %>);
                    }
                );
            }
        }
    }
    
    function loadmediapage(pageindex) {
        
        var status = $("#statuslist").val() + "";
        if (status.indexOf("all") == -1) {
            search(pageindex);
        }
        else {
            viewall(pageindex);
        }

    }
</script>

